package cc.imos.module.allow;

import cc.imos.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * Created by asher on 2017/4/23.
 */
@Repository
@CacheConfig(cacheNames = {"AllowRepository"})
public class AllowRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private Object[] args = new Object[] { true };

    @Cacheable
    public List<SysAccount> findSysAccountList() {
        String sql = "SELECT * FROM sys_account WHERE flag = ?";
        return jdbcTemplate.query(sql, args, new BeanPropertyRowMapper<>(SysAccount.class));
    }

    @Cacheable
    public List<SysAccountLine> findSysAccountLineList() {
        String sql = "SELECT * FROM sys_account_line WHERE flag = ?";
        return jdbcTemplate.queryForList(sql, args, SysAccountLine.class);
    }

    @Cacheable
    public List<SysAccountStatus> findSysAccountStatusList() {
        String sql = "SELECT * FROM sys_account_status";
        return jdbcTemplate.queryForList(sql, SysAccountStatus.class);
    }

    @Cacheable
    public List<SysAction> findSysActionList() {
        String sql = "SELECT * FROM sys_action WHERE flag = ?";
        return jdbcTemplate.query(sql, args, new BeanPropertyRowMapper(SysAction.class));
    }


    @Cacheable
    public List<SysStatus> findSysStatus() {
        String sql = "SELECT * FROM sys_status WHERE flag = ?";
        return jdbcTemplate.query(sql, args, new BeanPropertyRowMapper(SysStatus.class));
    }

    @Cacheable
    public List<SysStatusAction> findSysStatusActionList() {
        String sql = "SELECT * FROM sys_status_action";
        return jdbcTemplate.queryForList(sql, SysStatusAction.class);
    }

}
